package me.leiusual.sharing.util.extension

import androidx.annotation.IdRes
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.view.forEach
import androidx.core.view.isVisible
import androidx.core.widget.ContentLoadingProgressBar

/**
 * 切换显示
 */
fun <T : ConstraintLayout> T.switchView(@IdRes idRes: Int) {
  switchView(listOf(idRes))
}

/**
 * 切换显示
 */
fun <T : ConstraintLayout> T.switchView(@IdRes idRes: List<Int>) {
  forEach {
    when (it) {
      is ContentLoadingProgressBar -> if (it.id in idRes) it.show() else it.hide()
      else -> it.isVisible = it.id in idRes
    }
  }
}